package com.ywk.websocket.server;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;

/**
 * 浏览器在线测试：http://www.jsons.cn/websocket/
 * @Author zbh
 * @Date 2023/5/3
 */
@ServerEndpoint("/ws")
@Component
@Slf4j
public class WebSocketServer {

    @OnOpen
    public void onOpen(Session var1, EndpointConfig var2){
        log.info("连接成功");
    }

    @OnClose
    public void onClose(Session session, CloseReason closeReason) {
        log.info("连接关闭");
    }

    @OnError
    public void onError(Session session, Throwable throwable) {
        log.info("连接出错");
    }

    @OnMessage
    public void onMessage(String var1){
        log.info("接收信息：{}",var1);
    }

}
